package com.linghang.demo.controller;

import com.linghang.demo.domain.Homepic;
import com.linghang.demo.req.HomepicQueryReq;
import com.linghang.demo.req.HomepicSaveReq;
import com.linghang.demo.resp.CommonResp;
import com.linghang.demo.resp.HomepicQueryResp;
import com.linghang.demo.resp.PageResp;
import com.linghang.demo.service.HomepicService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

//首页下方图片
@RestController
@RequestMapping ("/home-low")
public class HomePicController {


    @Resource
    private HomepicService homepicService;


    @GetMapping("/list1")
    public CommonResp list() {
        CommonResp<List<Homepic>> resp = new CommonResp<>();
        List<Homepic> list = homepicService.list();
        resp.setContent(list);
        return resp;
    }
    @GetMapping("/list")
    public CommonResp list(@Valid HomepicQueryReq req) {
        CommonResp<PageResp<HomepicQueryResp>> resp = new CommonResp<>();
        PageResp<HomepicQueryResp> list = homepicService.list(req);
        resp.setContent(list);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable int id){
        CommonResp resp=new CommonResp<>();
        homepicService.delete(id);

        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody HomepicSaveReq req) {
        CommonResp resp = new CommonResp<>();
        homepicService.save(req);
        return resp;
    }
}